﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dotNetTraining.Exercise
{
    // Create Class Person
    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public List<Person> ListFr = new List<Person>();
    }
    public class Excercise
    {
        #region 31. Print number from 1 to 100 with these requirements:
        /// <summary>
        /// Print number from 1 to 100
        /// If the number is divisible by 3, print 'buzz' instead; If the number is divisible by 5, print 'fizz' instead;
        /// If the number is divisible by both 3 and 5, print 'buzz fizz'
        /// </summary>
        public static void PrintNumber()
        {
            for (var i = 1; i <= 100; i++)
            {
                Console.WriteLine((i % 3 == 0 && i % 5 == 0) ? "buzz fizz" : (i % 3 == 0) ? "buzz" : (i % 5 == 0) ? "fizz" : i.ToString());
            }
        }
        #endregion
        #region 32. Revert string by word.


        /// <summary>
        /// Revert String.
        /// Example: Input = "Hello Vinh , I am Thanh"
        /// Output: "Thanh am I , Vinh Hello"
        /// </summary>
        /// <param name="stringValue"></param>
        /// <returns></returns>
        public static string RevertString(string stringValue)
        {
            string result = string.Empty;

            string[] arr = stringValue.Split(' ');
            for (var i = 0; i < arr.Length; i++)
            {
                result += arr[arr.Length - i - 1] + " ";
            }

            return result;
        }
        /// <summary>
        /// Revert String.
        /// Example: Input = "Hello Vinh , I am Thanh"
        /// Output: "Thanh am I , Vinh Hello"
        /// using funtion Reverse
        /// </summary>
        /// <param name="stringValue"></param>
        /// <returns>string</returns>
        public static string RevertString2(string stringValue)
        {
            var str = stringValue.Split(' ');
            Array.Reverse(str);           
            return String.Join(" ",str).Trim();
        }
        #endregion
        #region Find words which is a part of another words


        /// <summary>
        /// Find words which is a part of another words
        /// </summary>
        /// <param name="strValue">Ex: "team beenext drink tea catching bee buy bamboo play seagame in the sea"</param>
        /// <returns>Ex: "output tea bee in sea"</returns>
        public static void FindString(string strValue)
        {

            int i = 0;
            string[] input = strValue.Split(' ');
            for (int j = 0; j < input.Count() - 1; j++)
            {
                for (int k = j; k < input.Count(); k++)
                {
                    if (input[k].Contains(input[j]))
                    {
                        ++i;
                    }

                }
                if (i > 1)
                    Console.WriteLine(input[j]);
                i = 0;
            }
        }
        #endregion
        #region 33.Give two classes A, B as bellow:

        public class A
        {
            public void Do()
            {
                Console.WriteLine("Do A");
            }
        }

        public class B : A
        {
            public void Do()
            {
                Console.WriteLine("Do B");
            }
        }

        public struct Point
        {
            public int x, y;
            public Point(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
        }
        #endregion
        #region 35. Remove duplicate elements of a given array.
        /// <summary>
        /// Remove duplicate elements of a given array.
        /// 1,2,1,3,1,4,4 => 1,2,3,4
        /// </summary>
        /// <param name="a"></param>
        public static void RemoveDuplicate(int[] a)
        {
            List<int> Lint = a.ToList();
            for (int i = 0; i < Lint.Count - 1; i++)
            {
                for (int j = i + 1; j < Lint.Count; j++)
                {
                    if (Lint[i] == Lint[j])
                        Lint.RemoveAt(j);
                }
            }
            foreach (int i in Lint)
            {
                Console.Write(i);
            }
        }
        #endregion
        #region 36 Illustrate a social network, object E knows F, object F knows object G, object G knows object H.
        /// <summary>
        /// Create Object Person and Friend
        /// </summary>
        public static void Friend()
        {
            Person men3 = new Person()
            {
                Name = "Men3",
                Age = 12,
            };
            Person men2 = new Person()
            {
                Name = "Men2",
                Age = 12,
                ListFr = new List<Person>(){
                    men3                
                }
            };
            Person men1 = new Person()
            {
                Name = "Men1",
                Age = 11,
                ListFr = new List<Person>(){
                    men2                   
                }
            };
            Person men4 = new Person()
            {
                Name = "Men4",
                Age = 14,
                ListFr = new List<Person>(){
                    men1                   
                }
            };
            foreach (Person pp in men4.ListFr)
            {
                Xuat(men4);
            }
            Console.ReadLine();
        }
        static void Xuat(Person p)
        {
            if (p.ListFr != null)
                foreach (Person p1 in p.ListFr)
                {
                    Console.Write(p1.Name + " ");
                    Console.WriteLine(p1.Age);
                    if (p1.ListFr != null)
                        Xuat(p1);
                }
        }
        #endregion
        #region 37. Let's capitalize the first letter of each word in string "hello yen my name is Thanh. And this is my house. You and me are having interview". But ignore these words: in, is, are. 
       /// <summary>
        /// Let's capitalize the first letter of each word.
       /// </summary>
       /// <param name="Value"></param>
       /// <returns>string</returns>
        public static string UperFirstLetter(string Value)
        {
            var str = Value.Split(' ');
            string[] temp = new string[] { "are","in","a","an","at","on","is","and"};
            string result = string.Empty;
            foreach (string s in str)
            {
                if (s.Length > 1 && !temp.Contains(s)) {
                    result +=s.Substring(0,1).ToUpper() +s.Substring(1).ToLower()+" ";
                }
                else result += s+" ";
            }
            return result;
        }
        #endregion
        #region 38. Find elements in array A but not exist in array B. 
        public static void FindNotExist(int []a,int []b)
        {
            //Array A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} 
            //Array B = {1, 3, 5, 7, 9, 11, 13} 
            foreach (int i in a)
            {
                if (!b.Contains(i))
                    Console.WriteLine(i);
            }
        }
        #endregion
    }

}
